package com.shop.technicalservice.dao.role.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.shop.technicalservice.dao.role.FunctionsDao;
import com.shop.technicalservice.model.role.Functions;

/**
 * A data access object (DAO) providing persistence and search support for
 * Functions entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see org.rjb.pojo.FunctionsDto
 * @author MyEclipse Persistence Tools
 */

public class FunctionsDaoImpl extends HibernateDaoSupport implements  FunctionsDao{
	private static final Log log = LogFactory.getLog(FunctionsDaoImpl.class);
	// property constants
	public static final String NAME = "name";
	public static final String URL = "url";

	protected void initDao() {
		// do nothing
	}

	public Functions save(Functions transientInstance)  throws Exception{
		log.debug("saving Functions instance");
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
			return transientInstance;
	}

	public void delete(Functions persistentInstance)  throws Exception{
		log.debug("deleting Functions instance");
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
	}

	public Functions findById(java.lang.Integer id)  throws Exception{
		log.debug("getting Functions instance with id: " + id);
			Functions instance = (Functions) getHibernateTemplate().get(
					"org.rjb.Functions", id);
			return instance;
	}

	public List findByExample(Functions instance)  throws Exception{
		log.debug("finding Functions instance by example");
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
	}

	public List findByProperty(String propertyName, Object value) throws Exception {
		log.debug("finding Functions instance with property: " + propertyName
				+ ", value: " + value);
			String queryString = "from Functions as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
	}

	public List findByName(Object name)  throws Exception{
		return findByProperty(NAME, name);
	}

	public List findByUrl(Object url)  throws Exception{
		return findByProperty(URL, url);
	}

	public List findAll()  throws Exception{
		log.debug("finding all Functions instances");
			String queryString = "from Functions";
			return getHibernateTemplate().find(queryString);
	}

	public Functions merge(Functions detachedInstance)  throws Exception{
		log.debug("merging Functions instance");
			Functions result = (Functions) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
	}

	public void attachDirty(Functions instance)  throws Exception{
		log.debug("attaching dirty Functions instance");
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
	}

	public void attachClean(Functions instance)  throws Exception{
		log.debug("attaching clean Functions instance");
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
	}

	public static FunctionsDaoImpl getFromApplicationContext(ApplicationContext ctx) {
		return (FunctionsDaoImpl) ctx.getBean("FunctionsDAO");
	}
}